//
//  JQFYGratefulMusicianCell.m
//  JQFY
//
//  Created by 代辉 on 2017/10/30.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYGratefulMusicianCell.h"
#import "JQFYGratefulMusicianCollectionViewCell.h"

@interface JQFYGratefulMusicianCell () <UICollectionViewDelegate,UICollectionViewDataSource>

@end

static NSString *_GRATEFUL_MUSICIAN_ = @"_GRATEFUL_MUSICIAN_";

@implementation JQFYGratefulMusicianCell{
    UICollectionView *_collection;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor clearColor];
    UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
    flowLayout.itemSize = CGSizeMake(120*SCAL, 331 *0.5 *SCAL);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _collection = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    _collection.contentInset = UIEdgeInsetsMake(0, 10 *SCAL, 0, 10 *SCAL);
    [_collection registerClass:[JQFYGratefulMusicianCollectionViewCell class] forCellWithReuseIdentifier:_GRATEFUL_MUSICIAN_];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.backgroundColor = [UIColor clearColor];
    _collection.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_collection];
    [_collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.songs.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JQFYGratefulMusicianCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_GRATEFUL_MUSICIAN_ forIndexPath:indexPath];
    cell.songInfo = self.songs[indexPath.row];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"HotMusician" object:indexPath];
}

- (void)setSongs:(NSArray *)songs
{
    _songs = songs;
    [_collection reloadData];
}
@end
